
const localStorageKey = 'addContainerFields'

export default {
  data(){
    return {
      rememberFields: ['startPort', 'targetPort', 'boxWeight', 'customBroker', 'customClearance'], // 将这些字段存入缓存中 下次自动填充
      rememberObj: null,
    }
  },
  methods: {
    // 设置对应的值到缓存上
    setLocalStorage(currentForm) {
      if(!this.rememberObj){
        this.rememberObj = {}
      }
      for (let currentFormKey in currentForm) {
        if(this.rememberFields.includes(currentFormKey) && currentForm[currentFormKey] !== ''){
          this.rememberObj[currentFormKey] = currentForm[currentFormKey]
        }
      }
      localStorage.setItem(localStorageKey, JSON.stringify(this.rememberObj))
    },
    // 获取缓存
    getLocalStorage() {
      let obj = localStorage.getItem(localStorageKey)
      if(!obj){
        return null
      }
      this.rememberObj = JSON.parse(obj)
      return this.rememberObj
    }
  }
}
